#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <error.h>

#define serv_ip "212.64.35.25"
#define port 3000

int main()
{
    pid_t pid;
    struct sockaddr_in servaddr;
    int addr_len;
    addr_len = sizeof(servaddr);

    bzero(&servaddr, addr_len);

    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(port);
    servaddr.sin_addr.s_addr = inet_addr(serv_ip);

    while(1)
    {
        int pid = fork();
        if (pid == 0)
        {
            int sockfd;
            if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
            {
                perror("fail to socket: ");
                exit(EXIT_FAILURE);
            }

            if ((connect(sockfd, (struct sockaddr *)&servaddr, addr_len)) == -1)
            {
                perror("fail to connect");
                exit(EXIT_FAILURE);
            }
            int recv_len;
            char buf[4096];
            bzero(buf, sizeof(buf));
            while(recv_len = read(sockfd, buf, sizeof(buf)) > 0)
            {
                printf("%s", buf);
            }
            exit(EXIT_SUCCESS);
        }
    }
    exit(EXIT_SUCCESS);
}